package Com.Isman.Adapter;

import java.util.List;

import Com.Isman.Booking.PageBooking;
import Com.Isman.Booking.R;
import Com.Isman.WebService.ComplexType.Hotel;
import Com.Isman.WebService.ComplexType.Room;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HotelRoomAdapter extends BaseAdapter {
    private final Context context;
    private final Hotel hotel;
    private final List<Room> list;
    
    public HotelRoomAdapter(Context contact, List<Room> list,Hotel hotel){
    	this.context = contact;
    	this.list = list;
    	this.hotel = hotel;
    }
    
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
      final Room entry = list.get(position);
      
      if (convertView == null) {
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.itemroomlist, null);
      }
      
      //findResource
      TextView roomname 	= (TextView)convertView.findViewById(R.id.lblItemRoomName);
      TextView status 		= (TextView)convertView.findViewById(R.id.lblItemRoomStatus);
      TextView price 		= (TextView)convertView.findViewById(R.id.lblItemRoomPrice);
      TextView badsize 		= (TextView)convertView.findViewById(R.id.lblItemBadSize);
      @SuppressWarnings("unused")
	ImageView roomImage	= (ImageView)convertView.findViewById(R.id.imgRoomImage);
      
      
      //Set value. 
      roomname.setText(entry.getRoomName());
      status.setText((entry.getAvailable() == 0 ? "Not available" : "Available"));
      price.setText(entry.getPrice()+" us");
      badsize.setText(entry.getBadSize());

        convertView.setOnClickListener(new  View.OnClickListener() { 
        	@Override
			public void onClick(View v) {
         		Intent intent = new Intent(v.getContext(),PageBooking.class);
        		intent.putExtra(PageBooking.BOOKING_LIST, hotel);
        		v.getContext().startActivity(intent);
        	}
		});
        return convertView;
	}

}
